package co.fitstart.entity.user.investigation;

import java.beans.Transient;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import co.fitstart.entity.user.User;

/**
 * 
 * @author mohanlan
 *
 */
@Entity
@Table(name = "participate_investigation")
@DynamicUpdate
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class ParticipateInvestigation {
    
    @Id
    @GeneratedValue
    private Long id;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JSONField(serialize = false)
    private User user;
    
    /** 创建时间 */
    private Date createTime;
    
    /** 渠道 来源 */
    @Enumerated(EnumType.ORDINAL)
    private Source source;
    
    /** 其他渠道 来源 */
    private String sourceRemarks;
    
    /** 参与原因 */
    @Enumerated(EnumType.ORDINAL)
    private Reason reason;
    
    /** 其他参与原因 */
    private String reasonRemarks;
    
    /** 期望 */
    @Enumerated(EnumType.ORDINAL)
    private Expectation expectation;
    
    /** 其他期望 */
    private String expectionRemarks;
    
    /** 参营号 */
    private String camp;
    
    /** 督教名称 */
    private String coach;
    
    /**
     * The default constructor
     */
    public ParticipateInvestigation() {
        
    }

    /**
     * 
     * @param participateInvestigation
     * @return
     */
    public ParticipateInvestigation edit(ParticipateInvestigation participateInvestigation) {
        
        this.source = participateInvestigation.getSource();
        this.sourceRemarks = participateInvestigation.getSourceRemarks();
        this.expectation = participateInvestigation.getExpectation();
        this.expectionRemarks = participateInvestigation.getExpectionRemarks();
        this.reason = participateInvestigation.getReason();
        this.reasonRemarks = participateInvestigation.getReasonRemarks();
        this.camp = participateInvestigation.getCamp();
        this.coach = participateInvestigation.getCoach();
        
        return this;
    }

    public ParticipateInvestigation initialize() {
        this.createTime = new Date();
        return this;
    }

    /**
     * 
     * @param user
     * @return
     */
    public ParticipateInvestigation bindUser(User user) {
        this.user = user;
        return this;
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public String getInvestigationSource() {
        if (this.source == null) {
            return this.sourceRemarks;
        }
        return this.source.getDescription() + this.sourceRemarks;
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public String getInvestigationReason() {
        if (this.reason == null) {
            return this.reasonRemarks;
        }
        return this.reason.getDescription() + this.reasonRemarks;
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public String getInvestigationExpectation() {
        if (this.expectation == null) {
            return this.expectionRemarks;
        }
        return this.expectation.getDescription() + this.expectionRemarks;
    }

    public Long getId() {
        return id;
    }

    public User getUser() {
        return user;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public Source getSource() {
        return source;
    }

    public String getSourceRemarks() {
        return sourceRemarks;
    }

    public Reason getReason() {
        return reason;
    }

    public String getReasonRemarks() {
        return reasonRemarks;
    }

    public Expectation getExpectation() {
        return expectation;
    }

    public String getExpectionRemarks() {
        return expectionRemarks;
    }

    public String getCamp() {
        return camp;
    }

    public String getCoach() {
        return coach;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public void setSource(Source source) {
        this.source = source;
    }

    public void setSourceRemarks(String sourceRemarks) {
        this.sourceRemarks = sourceRemarks;
    }

    public void setReason(Reason reason) {
        this.reason = reason;
    }

    public void setReasonRemarks(String reasonRemarks) {
        this.reasonRemarks = reasonRemarks;
    }

    public void setExpectation(Expectation expectation) {
        this.expectation = expectation;
    }

    public void setExpectionRemarks(String expectionRemarks) {
        this.expectionRemarks = expectionRemarks;
    }

    public void setCamp(String camp) {
        this.camp = camp;
    }

    public void setCoach(String coach) {
        this.coach = coach;
    }
}
